<template>
    <div class="content">
        <SearchTitle @searchClick="SearchTitleClick" />
        <div class="CenterBox">
            <div class="fhanBox" @click="fanhuifun">&lt;返回</div>
            <el-card>
                <template #header>
                    <div class="card-header">
                        <span style="color: #0084FF;font-weight: bold;font-size: 16px;">企业</span>
                    </div>
                </template>
                <div class="jsflexBox">
                    <div class="jsflexLabel">县区区域</div>
                    <div class="jsRightFlex">
                        <div :class="{ active: parameterData.regionId === item.dictValue }"
                            v-for="item in sysRegionData" :key="item.id" 
                            @click="xqTasbsfun(item.dictValue)" >
                            {{ item.dictLabel }}
                        </div>
                    </div>
                </div>
                <div class="jsflexBox">
                    <div class="jsflexLabel">企业类型</div>
                    <div class="jsRightFlex">
                        <div :class="{ active: parameterData.type === item.dictValue }"
                            v-for="item in sysEnterpriseTypeData" :key="item.id" 
                            @click="qylxTasbsfun(item.dictValue)" >
                            {{ item.dictLabel }}
                        </div>
                    </div>
                </div>
                <div class="jsflexBox">
                    <div class="jsflexLabel">成立年限</div>
                    <div class="jsRightFlex">
                        <div :class="{ active: parameterData.establishDate === item.date }"
                            v-for="item in dateData" :key="item.date"
                            @click="sjTasbsfun(item.date)" >
                            {{ item.name }}
                        </div>
                    </div>
                </div>
            </el-card>
            <el-card style="margin-top: 20px;">
                <div class="totalTextBox">
                    <span>为你推荐</span>
                    <span style="color: #F02B2B;margin: 0 10px;">{{ totalData }}</span>
                    <span>家符合条件的企业</span>
                </div>
                <EnterpriseInformationList :qyList="rzqyxxData" />
                <div class="fenyeBox">
                    <el-pagination v-model:current-page="parameterData.pageNum"
                        v-model:page-size="parameterData.pageSize" :page-sizes="[100, 200, 300, 400]" background
                        layout="prev, pager, next, jumper" :total="totalData" @current-change="handleCurrentChange" />
                </div>
            </el-card>
        </div>
    </div>
</template>
<script setup>
import SearchTitle from '@/components/general/SearchTitle.vue';
import EnterpriseInformationList from '@/components/general/EnterpriseInformationList.vue';
import { queryEnterpriseList } from '@/api/api.js';
import { sysEnterpriseType, sysRegion } from '@/api/dictionary.js';
import { ref, onMounted } from "vue";
import { getMonthsBefore, getYearsBefore } from '@/utils/time';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
onMounted(() => {
    // 顶部搜索跳转进来的
    if (route.query.searchType) {
        parameterData.value.name = route.query.name;
    }
    sysEnterpriseTypefun()
    sysRegionfun()
    queryEnterpriseListfun()
})
const parameterData = ref({
    page: 1,
    limit: 10,
    type: '',
    regionId: '',
    establishDate: '',
})
const totalData = ref(0);
const rzqyxxData = ref([]);
const queryEnterpriseListfun = async () => {
    const res = await queryEnterpriseList(parameterData.value)
    totalData.value = res.count
    rzqyxxData.value = res.data.map(item => {
        return {
            ...item,
            logo: item.picture.find(a => a.attachment_type === 'LOGO')?.file_path || ''
        };
    })
}
// 顶部搜索点击事件
const SearchTitleClick = (name) => {
    parameterData.value.name = name;
    parameterData.value.pageNum = 1;
    queryEnterpriseListfun()
}
const dateData = ref([
    {
        date: '',
        name: '全部'
    },
    {
        date: getMonthsBefore(3),
        name: '近三月'
    },
    {
        date: getMonthsBefore(6),
        name: '近半年'
    },
    {
        date: getYearsBefore(1),
        name: '近一年'
    },
    {
        date: getYearsBefore(3),
        name: '近三年'
    },
    {
        date: getYearsBefore(5),
        name: '近五年'
    },
    {
        date: getYearsBefore(10),
        name: '近十年'
    },
    {
        date: getYearsBefore(15),
        name: '近十五年'
    },
    {
        date: getYearsBefore(20),
        name: '近二十年'
    },
])
const sysEnterpriseTypeData = ref([]);
const sysEnterpriseTypefun = async () => {
    const res = await sysEnterpriseType()
    sysEnterpriseTypeData.value = [
        {
            dictLabel: '全部',
            dictValue: ''
        },
        ...res.data
    ]
}
const sysRegionData = ref([]);
const sysRegionfun = async () => {
    const res = await sysRegion()
    sysRegionData.value = [
        {
            dictLabel: '全部',
            dictValue: ''
        },
        ...res.data
    ]
}
const xqTasbsfun = (val) => {
    parameterData.value.regionId = val;
    parameterData.value.pageNum = 1
    queryEnterpriseListfun()
}
const qylxTasbsfun = (val) => {
    parameterData.value.type = val;
    parameterData.value.pageNum = 1
    queryEnterpriseListfun()
}
const sjTasbsfun = (val) => {
    parameterData.value.establishDate = val;
    parameterData.value.pageNum = 1
    queryEnterpriseListfun()
}
const handleCurrentChange = (val) => {
    parameterData.value.pageNum = val;
    queryEnterpriseListfun()
}
const fanhuifun = () => {
    router.go(-1);
};
</script>
<style scoped lang="scss">
.content {
    width: 100%;
    height: 100%;
    padding-bottom: 60px;
    min-height: 100vh;
    background-size: 100%;
    background-color: #f3f9fe;
}

.fhanBox {
    font-size: 16px;
    color: #767879;
    margin: 10px 0;
    cursor: pointer;

    &:hover {
        color: $green-color;
    }
}

.jsflexBox {
    display: flex;
    margin-bottom: 20px;

    .jsflexLabel {
        width: 8%;
        font-size: 14px;
        color: #000000;
    }

    .jsRightFlex {
        display: flex;
        gap: 15px;
        font-weight: 300;
        font-size: 14px;
        color: #000000;
        cursor: pointer;
    }
}

.totalTextBox {
    font-weight: 300;
    font-size: 14px;
    color: #1F1F1F;
    padding-bottom: 10px;
}

.fenyeBox {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #F1F1F1;
    padding-top: 20px;
}
.active {
    color: #2972FA;
    font-weight: bold;
}
</style>